﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
namespace MvcLibrary.Repository
{
    public class ImageHelper
    {
        public string encodeImageFile(HttpPostedFileBase file)
        {
            // extract only the fielname
            var fileName = Path.GetFileName(file.FileName);
            string ext = Path.GetExtension(file.FileName);
            ext = ext.ToLower();
            if (ext != ".jpg" && ext != ".jpeg" && ext != ".png" && ext != ".gif") // check file hinh
                return "!";

            // store the file inside folder
            string milisecond = DateTime.Now.Millisecond.ToString();
            fileName = fileName + DateTime.Now.ToLongDateString() + milisecond;

            MvcLibrary.Repository.Security ser = new MvcLibrary.Repository.Security();
            string encodeFileName = ser.GetHashPassword(fileName); // ma hoa file hinh

            encodeFileName += ext;
            return encodeFileName;
        }
    }
}